package com.jiyun.play.controller;


import com.domain.PlayersApplication;
import com.jiyun.play.config.AliyunOSSUtils;
import com.jiyun.play.service.IPlayersApplicationService;
import com.spyx.common.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.InputStream;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author sy
 * @since 2024-12-19
 */
@RestController
@RequestMapping("/players-application")
public class PlayersApplicationController {
    private final IPlayersApplicationService iPlayersApplicationService;

    @Autowired
    private AliyunOSSUtils aliyunOSSUtils;


    public PlayersApplicationController(IPlayersApplicationService iPlayersApplicationService) {
        this.iPlayersApplicationService = iPlayersApplicationService;
    }

    @GetMapping("/list")
    public List<PlayersApplication> list(){
        return iPlayersApplicationService.list();
    }

    @PostMapping("/applyfor")
    public Result applyfor(@RequestBody PlayersApplication playersApplication){
        return iPlayersApplicationService.applyfor(playersApplication);
    }

    @PostMapping("/fileUpload")
    public String upload(@RequestParam("file") MultipartFile file) throws Exception {
        String originalFilename = file.getOriginalFilename();
        InputStream inputStream = file.getInputStream();
        System.out.println(inputStream+"===========");
        String s=aliyunOSSUtils.putObject(inputStream,originalFilename);
        return s;
    }
}
